#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdint.h>
#include <string.h>

#include "od_thread.h"
#include "od_time.h"
#include "od_tube.h"
#include "od_os.h"
#include "od_trace.h"
#include "param_json.h"
#include "other2json.h"
#include "json_rpc.h"
#include "od_engine.h"
#include "od_framework.h"
#include "od_task.h"
#include "param_rpc.h"
#include "od_udp_send.h"


#include "console_param.h"
#include "sw_monitor.h"
#include "check_vid.h"
#include "ui_defines.h"
#include "media.h"


static void * sw_monitor_static_create(void *usr, char * task_name)
{
    sw_monitor_static_params *static_params = NULL;
    json_param_console * sw_monitor_params = usr;

    static_params = (sw_monitor_static_params *)od_malloc(sizeof(sw_monitor_static_params));
    if(NULL == static_params)
    {
        RPTERR("malloc falied");
        return NULL;
    }

    strncpy(static_params->tsk_name, task_name, OD_MAX_OBJ_NAME - 1);
    strncpy(static_params->post_name, sw_monitor_params->post_name, OD_MAX_PATH_LEN - 1);
    static_params->sw_monitor_id = sw_monitor_params->sw_monitor_id;
    static_params->notify_id = sw_monitor_params->notify_id;
    static_params->rpc_handle = sw_monitor_params->rpc_handle;

    return static_params;
}

static void * sw_monitor_dynamic_create(void *usr)
{
    sw_monitor_dynamic_params *dynamic_params = NULL;

    dynamic_params = (sw_monitor_dynamic_params *)od_malloc(sizeof(sw_monitor_dynamic_params));
    if (NULL == dynamic_params)
    {
       RPT(RPT_ERR, "NULL pointer, error");
       return NULL;
    }
    
    *dynamic_params = glb_sw_monitor_dynamic_params_default;
    
    /*if needed, add init dynamic param here*/

    return dynamic_params;
}

static const app_task_spawn_info_t app_list[]=
{
    {"sw_monitor", 87, 
        (void *)sw_monitor_static_create, (void *)sw_monitor_dynamic_create, (void *)sw_monitor_create,
    },
    {"", 0, 
        NULL, NULL, NULL,
    }
};

static task_name_t  console_starting_list[] =
{
    {"sw_monitor"},
};

/*启动对应板卡的framework，并且绑定参数生效和获取函数*/
int32_t console_start(od_framework_t * framework)
{
    int32_t ret = 0;
    json_param_console * params_obj = framework->param_table;

    ret |= od_framework_load(framework, app_list, console_starting_list, sizeof(console_starting_list)/sizeof(task_name_t));

    jsparam_act_all(params_obj->json_hdl);
    ret |= od_framework_start(framework, app_list, console_starting_list, sizeof(console_starting_list)/sizeof(task_name_t));

    return ret;
}

int32_t console_stop(od_framework_t * framework)
{
    int32_t ret = 0;

    ret = od_framework_stop(framework, console_starting_list, sizeof(console_starting_list)/sizeof(task_name_t));
    RPT(RPT_WRN,"od_framework_stop end");
    
    return ret;
}

